﻿using System;
using System.Management.Automation;
using Microsoft.ResourceManagement.ObjectModel;

namespace Quest.FIMPowerShellSnapin
{
    [Cmdlet(VerbsCommon.Remove, Constants.Nouns.FIMResource, SupportsShouldProcess = true)]
    public class RemoveFIMResource : PSCmdlet
    {
        private String _objectID;
        private FIMPSSession _session;

        [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
        [ValidateNotNullOrEmpty]
        public String ObjectID
        {
            get { return _objectID; }
            set { _objectID = value; }
        }

        [Parameter(Mandatory = true, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true)]
        [ValidateNotNullOrEmpty]
        public FIMPSSession Session
        {
            get { return _session; }
            set { _session = value; }
        }

        protected override void ProcessRecord()
        {
            bool shouldProcess = ShouldProcess(Constants.Messages.VerboseRemove, Constants.Messages.ConfirmRemove, _objectID);

            if (shouldProcess)
            {
                RmReference id = new RmReference(_objectID);
                _session.Client.Delete(id); //!!! should we do anything with the return value?
            }
        }
    }
}
